
local skynet = require 'skynet';
local log = require 'log';

local server_id = skynet.getenv 'server_id';
local server_index = skynet.getenv 'server_index';
local is_db_node = 1000 == tonumber(server_index);

skynet.start(function()
    log.notice("=====>My Server start<=====");
    skynet.uniqueservice("protod");

    local server_mgr = skynet.uniqueservice('us_server_mgr');

    -- local us_db_mgr = skynet.uniqueservice("us_db_mgr");
    -- skynet.call(us_db_mgr, "lua", "start");
    -- skynet.call(us_db_mgr, "lua", "test");

    -- 数据库服务
    if is_db_node then
        local db_service = skynet.uniqueservice('us_dbmgr');
        -- skynet.call(us_dbmgr, "lua", "start");
    else
        -- 房间管理服务
        local room_service = skynet.uniqueservice('us_room_mgr');

        local team_service = skynet.uniqueservice('us_team');

        local match_service = skynet.uniqueservice('us_match');

        local login_service = skynet.newservice("us_login");
        -- skynet.newservice("uslogin");
        local watchdog = skynet.newservice("us_watchdog")
        skynet.call(watchdog, "lua", "start_gate", {
            port = tonumber(skynet.getenv 'gate_port'),
            max_client = tonumber(skynet.getenv 'max_client') or 1024,
            login = login_service,
        })
    end

    skynet.exit()
end)

